package aufgabe_02;

import java.util.Vector;

public class Queue {

	private Vector vec;
	

	public Queue() {
		vec = new Vector();
	}

	public void insertMessage( Message mRef )
	{		
		int priority = mRef.getPriority();

	      //int aktpriority;
	      int lv = 0;
	     // Message aktRef;

	      try
	      {

	         while (((Message) vec.elementAt(lv)).getPriority()  >=
	                  priority ) lv++;

	         vec.insertElementAt (mRef, lv);

	      }
	      catch (Exception e)
	      {
	         vec.addElement (mRef);
	      }
	  }

		
	

	public Message extractMessage() {

	    if (vec.isEmpty()) return null;
	    else
	    {
	      Message mRef = (Message)vec.firstElement();
	      vec.removeElementAt(0);
	      return mRef;
	    }

	}
}
